package com.oplink.webems.modules.event;

import java.util.Collection;

import org.directwebremoting.ScriptSession;
import org.directwebremoting.WebContextFactory;
import org.directwebremoting.impl.DefaultWebContext;

/**
 * 保存session
 * @author yongz
 *
 */
public class WebSessionManager{
	
	static String currentPage;
	public static Collection<ScriptSession> sessions;
	static WebSessionManager instance;
	
	/**
	 * get new session
	 * @throws InterruptedException
	 */
	public synchronized void session2Server() throws InterruptedException {
		System.out.println("a session comming");
		DefaultWebContext wctx = (DefaultWebContext) WebContextFactory.get();
		if(wctx.getCurrentPage().equals(currentPage)){
			//update sessions
			sessions = wctx.getScriptSessionsByPage(currentPage);
			return;
		}
		//first get page, maybe the sentence is needless
		currentPage = wctx.getCurrentPage();
		//first initialize session
		sessions = wctx.getScriptSessionsByPage(currentPage);
	}
}
